import { takeEvery, put } from 'redux-saga/effects'
import { GET_INIT_LIST } from './actionType'
import { InitStateAction } from './actionCreators'
import axios from 'axios'

function* getInitList() {
  try {
    const res = yield axios.get('api/todolist')
    const action = InitStateAction(res.data)
    // 发送 请求 派发任务
    yield put(action)
  } catch (e) {
    console.log('异步请求失败')
  }

}

// generator 函数
function* todoSagas() {
  yield takeEvery(GET_INIT_LIST, getInitList)
}

export default todoSagas;